package com.ljl.ssm.controller;


import com.ljl.ssm.entity.Order;
import com.ljl.ssm.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author BaoZhou
 * @since 2019-07-07
 */
@Controller
@RequestMapping("/admin")
public class OrderController {
    @Autowired
    IOrderService orderService;

    @RequestMapping("/listOrder")
    public String list(Model model) {
        List<Order> orders = orderService.listAll();
        model.addAttribute("orders", orders);
        return "admin/listOrder";
    }

    @RequestMapping("updateOrder")
    public String update(Order order) {
        orderService.update(order);
        return "redirect:listOrder";
    }

    @RequestMapping("orderDelivery")
    public String delivery(Integer order_id) {
        Order order = orderService.get(order_id);
        order.setDeliveryDate(new Date());
        order.setStatus(IOrderService.waitConfirm);
        orderService.update(order);
        return "redirect:listOrder";
    }
}

